package com.hzit.controller;

import com.hzit.common.entity.R;
import com.hzit.entity.ItemCat;
import com.hzit.service.IItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品类目 前端控制器
 * </p>
 *
 * @author wf
 * @since 2023-08-07
 */
@RestController
@RequestMapping("/itemCat")
public class ItemCatController {

	@Autowired
	private IItemCatService itemCatService;

	//2. 根据父id查询子分类列表
	@GetMapping("/findItemCatsByParentId/{pid}")
	public R findCategorysByParentId(@PathVariable("pid") String pid){
		List<ItemCat> itemCatList = itemCatService.findCategorysByParentId(pid);
		return R.ok().put("itemCatList",itemCatList);
	}

	//3. 根据分尖id查询分类对象
	@GetMapping("/findById/{id}")
	public R findById(@PathVariable("id") Long id){
		ItemCat itemCat = itemCatService.getById(id);
		return R.ok().put("itemCat",itemCat);
	}
}
